package stdio.costa.moca.rest;

import stdio.costa.moca.ThreadLocalEntityManager;
import stdio.costa.moca.ThreadLocalSessionManager;

import com.sun.jersey.spi.container.ContainerRequest;
import com.sun.jersey.spi.container.ContainerRequestFilter;
import com.sun.jersey.spi.container.ContainerResponse;
import com.sun.jersey.spi.container.ContainerResponseFilter;

public class MocaContainerFilter extends RestfulOperations implements ContainerRequestFilter, ContainerResponseFilter {
	
	@Override
	public ContainerRequest filter(ContainerRequest request) {
		beginTransaction();
		return request;
	}

	@Override
	public ContainerResponse filter(ContainerRequest request, ContainerResponse response) {
		commitTransaction();
		ThreadLocalEntityManager.clear();
		ThreadLocalSessionManager.clear();
		return response;
	}
}
